package com.to8to.autotask.util;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import org.elasticsearch.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Constant.java
 * 作 者：atom.liu
 * 版 本：v2.0
 * 日 期：2015年2月6日
 * 描 述：常量类
 */
public final class Constant
{
    private static final Logger logger = LoggerFactory.getLogger(Constant.class);

    public static final CopyOnWriteArrayList<Integer> SPECIAL_CITY = new CopyOnWriteArrayList<Integer>();

    /**
     * 渠道：PC
     */
    public static final CopyOnWriteArrayList<String> CHANNEL_PC = new CopyOnWriteArrayList<String>();

    /**
     * 不考虑重复项目的手机号
     */
    public static final CopyOnWriteArrayList<String> ignoreRepeatedPhones = Lists.newCopyOnWriteArrayList();

    /**
     * 分配单个项目时，项目的ptag;由tom.zhang提供。
     */
    public static final String UPPROJECT_POPULARIZE_POST = "4_1_3_1";

    public static final int RECEIVE_STATUS_ALL = 0;

    public static final int RECEIVE_STATUS_PC = 4;

    public static final int RECEIVE_STATUS_APP = 3;

    /**
     * 初始化渠道配置信息，除了PC和H5之外，其他的全部属于APP
     */
    public static void initChannelInfo(Map<String, List<String>> map)
    {
        CHANNEL_PC.clear();

        for (String s : map.get("pc"))
            CHANNEL_PC.add(s + "_");

        StringBuilder sb = new StringBuilder("当前渠道对应Ptag信息：\r\n");
        sb.append("pc:").append(CHANNEL_PC);

        logger.info(sb.toString());
    }

    public static void initSpecCityInfo(String[] cityids)
    {
        SPECIAL_CITY.clear();

        for (String s : cityids)
        {
            try
            {
                SPECIAL_CITY.add(Integer.parseInt(s));
            }
            catch (NumberFormatException e)
            {
                logger.error("Integer.parseInt({})异常", s);
            }
        }

        logger.info("分配审核客服时，不按渠道过滤的城市 " + SPECIAL_CITY);
    }

    public static String getSpecCityStr()
    {
        if (SPECIAL_CITY.size() == 0)
            return "1130,2827";
        return Utils.collect2Str(SPECIAL_CITY);
    }

    /**
     * 初始化不考虑重复项目的手机号
     */
    public static void initIgnoreRepeatPhone(String[] phones)
    {
        ignoreRepeatedPhones.clear();
        if (phones == null || phones.length == 0)
            return;
        ignoreRepeatedPhones.addAll(Arrays.asList(phones));
        logger.info("当前分配时不需要考虑重复项目的手机号：" + ignoreRepeatedPhones);
    }
}
